--BY 久逢

--脚本号
x900094_g_scriptId = 900094

--所拥有的事件ID列表
x900094_g_eventList={}

x900094_g_SheepBuff = 31550											--变羊buff

--**********************************
--事件列表
--**********************************
function x900094_UpdateEventList( sceneId, selfId, targetId )
    all = GetMissionData(sceneId,selfId,MD_MJTYD)
	x900094_MsgBox( sceneId, selfId, targetId, all )
	
	BeginEvent(sceneId)
		AddText(sceneId,"#{QXLS_150724_04}")
		--AddNumText( sceneId, x900094_g_scriptId, "#{BHXZ_081103_75}", 4, 1 )
			AddNumText( sceneId, x900094_g_ScriptId, "#{QXLS_150724_05}", 6, 978)
			--AddNumText( sceneId, x900094_g_ScriptId, "#{QXLS_150724_06}", 6, 979)	
			--AddNumText( sceneId, x900094_g_ScriptId, "#{QXLS_150724_07}", 6, 980)	
			--AddNumText( sceneId, x900094_g_ScriptId, "#{QXLS_150724_08}", 6, 981)				
		--	AddNumText( sceneId, x900094_g_ScriptId, "#{JBHL_190803_49}", 6, 977)
		--	AddNumText( sceneId, x900094_g_ScriptId, "200", 6, 999)		
			--AddNumText( sceneId, x900094_g_ScriptId, "个人争霸赛", 6, 999)	 				
	EndEvent(sceneId)
	for i, eventId in x900094_g_eventList do
		CallScriptFunction( eventId, "OnEnumerate",sceneId, selfId, targetId )
	end
	EndEvent(sceneId)
	DispatchEventList(sceneId,selfId,targetId)

end

--**********************************
--事件交互入口
--**********************************
function x900094_OnDefaultEvent( sceneId, selfId,targetId )
	x900094_UpdateEventList( sceneId, selfId, targetId )
end

--
function ceshi() 
    Clear_XSCRIPT()
		Set_XSCRIPT_Function_Name("XiaoXiang_ServerCall")
		Set_XSCRIPT_ScriptID(920310)
		Set_XSCRIPT_Parameter( 0, tonumber( 3000 ) )
		Set_XSCRIPT_Parameter( 1, tonumber( 1 ) )
		Set_XSCRIPT_ParamCount(2)
    Send_XSCRIPT()
end
--**********************************
--事件列表选中一项
--**********************************

function x900094_OnEventRequest( sceneId, selfId, targetId, eventId )

	local	key	= GetNumText()
	if key == 999 then 
SetMissionData (sceneId,selfId,MD_SONGHUA,1888)
	end 
	if key == 981 then 
		-- 这里获取玩家的两个值
	local JF_songhua = GetMissionData(sceneId,selfId,MD_SONGHUA)	
	local JF_shouhua = GetMissionData(sceneId,selfId,MD_SHOUHUA)
	BeginEvent(sceneId)
		AddText(sceneId,"#{QXLS_150724_11}".."#{QXLS_150724_09}"..JF_songhua.."#{QXLS_150724_10}"..JF_shouhua)
		
		AddNumText( sceneId, x900094_g_ScriptId, "#{QXLS_150724_14}", 6, 982)
		AddNumText( sceneId, x900094_g_ScriptId, "#{QXLS_150724_15}", 6, 983)
		EndEvent(sceneId)
	DispatchEventList(sceneId,selfId,targetId)
	end 
	if key == 982 then  --送花值兑换 
    local JF_songhua = GetMissionData(sceneId,selfId,MD_SONGHUA)
      if JF_songhua < 1888 then 
	 x900094_NotifyTip( sceneId, selfId, "#{QXLS_150724_19}" )
	  return 
      end 	 

        if JF_songhua >= 1888 then 
		--执行扣除变量并给道具了 
		SetMissionData (sceneId,selfId,MD_SONGHUA,JF_songhua-1888)
		LuaFnTryRecieveItem(sceneId,selfId,20700075,1)  --道具需要改
	 x900094_NotifyTip( sceneId, selfId, "#{QXLS_150724_17}" )		
        end 		
	end
	if key == 983 then 
	local JF_shouhua = GetMissionData(sceneId,selfId,MD_SHOUHUA)
      if JF_shouhua < 1888 then 
	 x900094_NotifyTip( sceneId, selfId, "#{QXLS_150724_18}" )
      return	 
	  end
	     if JF_shouhua >= 1888 then 
		SetMissionData (sceneId,selfId,MD_SHOUHUA,JF_shouhua-1888) 
		LuaFnTryRecieveItem(sceneId,selfId,20700075,1)  --道具需要改
	 x900094_NotifyTip( sceneId, selfId, "#{QXLS_150724_17}" )			 
		 end
	end
		if key == 980 then
  --CallScriptFunction( 955557, "FeiHuaCangBaoGe_Open3",sceneId,selfId,1)
 	BeginEvent( sceneId )
				AddText( sceneId, " #{QXLS_150724_16}" )
			EndEvent( sceneId )
			DispatchEventList( sceneId, selfId, targetId )
  return
	end
	if key == 979 then
  CallScriptFunction( 955556, "FeiHuaCangBaoGe_Open2",sceneId,selfId,1)
	end	
	if key == 978 then
  CallScriptFunction( 955555, "FeiHuaCangBaoGe_Open",sceneId,selfId,1)
	end
	if key == 977 then
  local  hl1 =  LuaFnGetAvailableItemCount(sceneId, selfId, 38000485)
   local  hl2 =  LuaFnGetAvailableItemCount(sceneId, selfId, 38000486)
   local  hl3 =  LuaFnGetAvailableItemCount(sceneId, selfId, 38000828)  
   local  hl4 =  LuaFnGetAvailableItemCount(sceneId, selfId, 38001565)   
   local  hl5 =  LuaFnGetAvailableItemCount(sceneId, selfId, 38001568)   
   local  hl6 =  LuaFnGetAvailableItemCount(sceneId, selfId, 38001076)  
   local  hl7 =  LuaFnGetAvailableItemCount(sceneId, selfId, 38001077)  
   local hlzong = hl1+hl2+hl3+hl4+hl5+hl6+hl7
      if hlzong < 1 then 
   x900094_MsgBox(sceneId, selfId, targetId, "  #{JBHL_190803_52}")
   return 0 
   end 		
       if hlzong >= 1 then   
	   local hlzongz = 100*hl1 + 200*hl2 +500*hl3 + 1000*hl4 + 2000*hl5 + 10000* hl6 + 20000* hl7 
	LuaFnDelAvailableItem (sceneId,selfId,38000485,hl1)
	LuaFnDelAvailableItem (sceneId,selfId,38000486,hl2)
	LuaFnDelAvailableItem (sceneId,selfId,38000828,hl3)
	LuaFnDelAvailableItem (sceneId,selfId,38001565,hl4)
	LuaFnDelAvailableItem (sceneId,selfId,38001568,hl5)
	LuaFnDelAvailableItem (sceneId,selfId,38001076,hl6)
	LuaFnDelAvailableItem (sceneId,selfId,38001077,hl7)  -- 扣除完
	   x900094_MsgBox(sceneId, selfId, targetId, "  #{JBHL_190803_53}"..hlzongz.."#{JBHL_190803_54}")
	-- 给予 
		local locb = GetMissionData(sceneId,selfId,XYJ_HONGLI)
		SetMissionData(sceneId,selfId,XYJ_HONGLI,locb+hlzongz)
		
	  end 	
	 end
	if key == 1 then
		if LuaFnHaveImpactOfSpecificDataIndex(sceneId, selfId, x900094_g_SheepBuff) == 1 then
			LuaFnCancelSpecificImpact(sceneId,selfId,x900094_g_SheepBuff)
			BeginEvent( sceneId )
				AddText( sceneId, "  我已经给你变回来了，以后可要好好做人。" )
			EndEvent( sceneId )
			DispatchEventList( sceneId, selfId, targetId )
		else
			LuaFnCancelSpecificImpact(sceneId,selfId,x900094_g_SheepBuff)
			BeginEvent( sceneId )
				AddText( sceneId, "  你并没有变成羊啊。" )
			EndEvent( sceneId )
			DispatchEventList( sceneId, selfId, targetId )
		end
		return
	end

	for i, findId in x900094_g_eventList do
		if eventId == findId then
			CallScriptFunction( eventId, "OnDefaultEvent",sceneId, selfId, targetId, GetNumText() )	--GetNumText()是addnumtext中最后的变量
			return
		end
	end

end

--**********************************
--接受此NPC的任务
--**********************************
function x900094_OnMissionAccept( sceneId, selfId, targetId, missionScriptId )
	for i, findId in x900094_g_eventList do
		if missionScriptId == findId then
			ret = CallScriptFunction( missionScriptId, "CheckAccept", sceneId, selfId )
			if ret > 0 then
				CallScriptFunction( missionScriptId, "OnAccept", sceneId, selfId )
			end
			return
		end
	end
end

--**********************************
--拒绝此NPC的任务
--**********************************
function x900094_OnMissionRefuse( sceneId, selfId, targetId, missionScriptId )
	--拒绝之后，要返回NPC的事件列表
	for i, findId in x900094_g_eventList do
		if missionScriptId == findId then
			x900094_UpdateEventList( sceneId, selfId, targetId )
			return
		end
	end
end

--**********************************
--继续（已经接了任务）
--**********************************
function x900094_OnMissionContinue( sceneId, selfId, targetId, missionScriptId )
	for i, findId in x900094_g_eventList do
		if missionScriptId == findId then
			CallScriptFunction( missionScriptId, "OnContinue", sceneId, selfId, targetId )
			return
		end
	end
end

--**********************************
--提交已做完的任务
--**********************************
function x900094_OnMissionSubmit( sceneId, selfId, targetId, missionScriptId, selectRadioId )
	for i, findId in x900094_g_eventList do
		if missionScriptId == findId then
			CallScriptFunction( missionScriptId, "OnSubmit", sceneId, selfId, targetId, selectRadioId )
			return
		end
	end
end

function x900094_MsgBox( sceneId, selfId, targetId, str )

	BeginEvent( sceneId )
		AddText( sceneId, str )
	EndEvent( sceneId )
	DispatchEventList( sceneId, selfId, targetId )
	
end

--------
--中间字符串提示
--------
function x900094_NotifyTip( sceneId, selfId, Msg )
	BeginEvent( sceneId )
		AddText( sceneId, Msg )
	EndEvent( sceneId )
	DispatchMissionTips( sceneId, selfId )
end	